/*
 * debug.h
 *
 *  Created on: May 18, 2011
 *      Author: makkalot
 */

#ifndef DEBUG_H_
#define DEBUG_H_

/* Method definitions */
extern void dbg_printf(const char *fmt, ...);

/* DEBUG MACRO CONSTANTS */
#define LOG_LEVEL_DEBUG		0
#define LOG_LEVEL_INFO		1
#define LOG_LEVEL_WARN		2
#define LOG_LEVEL_ERR		3
#define LOG_LEVEL_FATAL		4

#ifdef DEBUG_LEVEL
#define DEFAULT_DEBUG_LEVEL DEBUG_LEVEL
#else
#define DEFAULT_DEBUG_LEVEL	LOG_LEVEL_FATAL
#endif

/* Debug Macro Functionality */
#ifdef DEBUG

#define LOG(debug_level, fmt) do {					\
	if((debug_level) >= DEFAULT_DEBUG_LEVEL)		\
		dbg_printf fmt;								\
}while(0)

#define LOG_DEBUG(fmt)	LOG(LOG_LEVEL_DEBUG, fmt)
#define LOG_INFO(fmt)	LOG(LOG_LEVEL_INFO, fmt)
#define LOG_WARN(fmt)	LOG(LOG_LEVEL_WARN, fmt)
#define LOG_FATAL(fmt)	LOG(LOG_LEVEL_FATAL, fmt)
#define LOG_ERR(fmt)	LOG(LOG_LEVEL_ERR, fmt)

#else

#define LOG(debug_level, fmt)
#define LOG_DEBUG(fmt)
#define LOG_ERR(fmt)
#define LOG_INFO(fmt)
#define LOG_WARN(fmt)
#define LOG_FATAL(fmt)

#endif

#endif /* DEBUG_H_ */
